import { Inject, Controller, Post, Body } from '@midwayjs/decorator';
import { Context } from '@midwayjs/koa'
import { MdDTO } from '../dto/md';

import { Validate } from '@midwayjs/validate';

import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { UserEntity } from '../entity/user';
import { MdService } from '../service/md.service';
import { SearchDTO } from '../dto/Search';




/**
 * 描述
 */
@Controller('/md')
export class APIController {
    @Inject()
    ctx: Context;


    @Inject()
    MdService: MdService

    @InjectEntityModel(UserEntity)
    userentity: Repository<UserEntity>;

    //  属性修饰符
    //  @Inject()
    // ClassifyService: ClassifyService;






    //  控制器只需要写路由 写校验
    @Post('/login')
    @Validate()
    async login(@Body() body: MdDTO) {
        // code  有效期 5分钟
        console.log(body.code);


        return this.MdService.login(body.code)
    }




    @Post('/uuid')
    @Validate()  // 加了这个修饰符 表示参数是会校验
    async addnovelitem(@Body() body: MdDTO) {
        console.log(body);

        return {
            name: "卓标"
        }

    }
    @Post('/getfood')
    async getfood() {

        return this.MdService.getfoods()

    }

    @Post('/getshopfood')
    async getshopfood(@Body() body: any) {

        return this.MdService.getshopfood(body.id)

    }


    @Post('/getclassify')
    async getclassify() {

        return this.MdService.getclassify()

    }


    @Post("/getshop")
    @Validate()
    async getshop(@Body() body: SearchDTO) {
        //   page  size  ,   
        return this.MdService.getshop(body)

    }





    @Post('/tosub')
    async tosub(@Body() body: any) {

        return this.MdService.tosubsrc(body.openid)

    }















}